import 'package:fire_chat/constant/font.dart';
import 'package:fire_chat/ui/login/page/short_login_page.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

///登录页面
class LoginPage extends StatefulWidget {
  const LoginPage({Key? key}) : super(key: key);

  @override
  _LoginPageState createState() => _LoginPageState();
}

class _LoginPageState extends State<LoginPage>
    with SingleTickerProviderStateMixin {
  //标题列表
  var tabTitle = [];

  //界面列表
  List<Widget> pageLists = [];

  //tab控制器
  late PageController pageController = PageController(initialPage: 0);
  int a = 0;

  @override
  void initState() {
    super.initState();
    tabTitle = ["短信登陆", "密码登录"];
    pageLists = [Center(child: Column(
      children: [
        Text('今日爆款',style: KFontConstant.myTextStyle(),),
        Container(
          width: 200.w,
          height: 200.h,
          color: Colors.black,
        )
      ],
    )),Center(child: Text('土货生鲜',style: KFontConstant.myTextStyle())),
      Center(child: Text('会员中心',style: KFontConstant.myTextStyle())),
      Center(child: Text('分类',style: KFontConstant.myTextStyle()))];
    // tabController = TabController(length: 4, vsync: this);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        bottomNavigationBar: BottomNavigationBar(
          backgroundColor: Colors.blue,
          selectedItemColor: Colors.blue,
          unselectedItemColor: Colors.black45,
          showUnselectedLabels: true,
          currentIndex: a,
          //实现底部导航栏点击选***能
          onTap: (int index){
// this._currentIndex=index;//不会重新渲染
            setState(() {
              a=index;
              pageController.animateToPage(index, duration: const Duration(milliseconds: 300), curve: Curves.ease);
            });
          },
          items: const [
            BottomNavigationBarItem(
                icon: Icon(Icons.home),
                title: Text("今日爆款")
            ),
            BottomNavigationBarItem(
                icon: Icon(Icons.category),
                title: Text("土货生鲜")
            ),
            BottomNavigationBarItem(
                icon: Icon(Icons.settings),
                title: Text("会员中心")
            ),BottomNavigationBarItem(
                icon: Icon(Icons.settings),
                title: Text("分类")
            )
          ],
        ),
        body: PageView.builder(
          controller: pageController,
            itemCount: pageLists.length,
            onPageChanged: (val){
              setState(() {
                a=val;
              });
            },
            itemBuilder: (context,index){
          return pageLists[index];
        }));
  }
  //
  // @override
  // void debugFillProperties(DiagnosticPropertiesBuilder properties) {
  //   super.debugFillProperties(properties);
  //   properties.add(
  //       DiagnosticsProperty<TabController>('tabController', tabController));
  // }
}
